<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="/tags" prefix="date" %>
<%@ include file="../inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
    <meta name="format-detection" content="telephone=no">
    <meta charset="UTF-8">
    <meta name="description" content="Violate Responsive Admin Template">
    <meta name="keywords" content="Super Admin, Admin, Template, Bootstrap">
    <title>Super Admin Responsive Template</title>
    <!-- CSS -->
    <%@ include file="../inc/new/css.jsp" %>
</head>
<body id="skin-cloth">
<%@ include file="../inc/new/header.jsp" %>
<div class="clearfix"></div>
<section id="main" class="p-relative" role="main">
    <input type="hidden" id="mian_module" value="用户管理">
    <input type="hidden" id="child_module" value="会员列表">
    <%@ include file="../inc/new/menu.jsp" %>
    <section id="content" class="container">
        <!-- Breadcrumb -->
        <ol class="breadcrumb hidden-xs">
            <li><a href="javascript:history.go(-1);" title="返回"><span class="icon">&#61771;</span></a></li>
        </ol>
        <h1 class="page-title">新增会员</h1>
        <form id="fromId" name="formName" method="post" enctype="multipart/form-data"
              class="box tile animated active form-validation-1">
            <div class="block-area">
                <div class="row">
                    <div class="col-md-6 m-b-15" style="margin-top: 0px;">
                        <label>头像:</label>
                        <div class="fileupload fileupload-new" data-provides="fileupload">
                            <div class="fileupload-preview thumbnail form-control">
                                <img src="">
                            </div>
                            <div>
                                <span class="btn btn-file btn-alt btn-sm">
                                    <span class="fileupload-new">选择图片</span>
                                    <span class="fileupload-exists">更改</span>
                                    <input id="imageFile" name="imageFile" type="file"/>
                                </span>
                                <a href="#" class="btn fileupload-exists btn-sm" data-dismiss="fileupload">移除</a>
                            </div>
                        </div>
                    </div>
                    <hr class="whiter m-t-20"/>
                    <div class="col-md-6 m-b-15" style="margin-top: 10px;">
                        <label>账号:</label>
                        <input type="text" id="mobile" value="" name="mobile" class="input-sm form-control validate[required]" placeholder="...">
                    </div>
                    <div class="col-md-6 m-b-15" style="margin-top: 10px;">
                        <label>密码:</label>
                        <input type="password" id="password" value="" name="password" class="input-sm form-control validate[required]" placeholder="...">
                    </div>
                    <div class="col-md-6 m-b-15" style="margin-top: 10px;">
                        <label>昵称:</label>
                        <input type="text" id="nickname" value="" name="nickname" class="input-sm form-control validate[required]" placeholder="...">
                    </div>
                    <div class="col-md-6 m-b-15" style="margin-top: 10px;">
                        <label>性别:</label>
                        <select id="gender" name="gender" style="width: 200px;" class="select">
                            <option value="">请选择性别</option>
                            <option value="0">男</option>
                            <option value="1">女</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-5">
                        <button type="button" onclick="user.fn.save();" class="btn btn-info btn-sm m-t-10">提交</button>
                        <button type="button" class="btn btn-info btn-sm m-t-10" onclick="history.go(-1);">返回</button>
                    </div>
                </div>
            </div>
        </form>
    </section>
    <br/><br/>
</section>
<!-- JS -->
<%@ include file="../inc/new/foot.jsp" %>
<script>
    var user = {
        v: {
            id: "post",
            list: [],
            dTable: null
        },
        fn: {
            init: function () {
                $.ajaxSetup({
                    async: false
                });

            },
            checkData: function () {
                var flag = true;
                var mobile1 = $('#mobile').val();
                var password1 = $('#password').val();
                var nickName1 = $('#nickname').val();
                var gender = $('#gender').val();

                if (null == mobile1 || mobile1 == '') {
                     $common.fn.notify("请输入账号", "error");
                     flag = false;
                     return;
                }

                if(!/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(mobile1)) {
                    $common.fn.notify("账号不合法，请输入正确的手机号", "error");
                    flag = false;
                    return;
                }

                if (null == password1 || password1 == '') {
                    $common.fn.notify("请输入密码", "error");
                    flag = false;
                    return;
                }

                if (null == nickName1 || nickName1 == '') {
                    $common.fn.notify("请输入昵称", "error");
                    flag = false;
                    return;
                }

                if (nickName1.length > 6) {
                     $common.fn.notify("昵称字数不能超过6字符", "error");
                     flag = false;
                     return;
                }

                if (null == gender || gender == '') {
                    $common.fn.notify("请选择性别", "error");
                    flag = false;
                    return;
                }

                return flag;
            },
            save: function () {
                if (user.fn.checkData()) {

                    $("#fromId").ajaxSubmit({
                        url: "${contextPath}/admin/user/save",
                        type: "POST",
                        data: {
                        },
                        success: function (result) {
                            if (result == 1) {
                                $common.fn.notify("操作成功", "success");
                                window.location.href = "${contextPath}/admin/user/index";
                            } else if (result == 2){
                                $common.fn.notify("昵称已存在，请重新输入", "error");
                            } else if (result == 3){
                                $common.fn.notify("昵称包含敏感词，请重新输入", "error");
                            } else if (result == 4){
                                $common.fn.notify("账号已存在，请重新输入", "error");
                            }
                            else {
                                $common.fn.notify("操作失败", "error");
                            }
                        }
                    });
                }
            },
        }
    }
    $(function () {
        user.fn.init();
    })
</script>
<script>
    $('.form_datetime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: "2",
        forceParse: 0,
        showMeridian: 1,
        format: 'yyyy-mm-dd'
    });
</script>
</body>
</html>

